home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / delcol10.zip / DELCOL.C next >
C/C++ Source or Header  |  1993-06-09  |  3KB  |  83 lines

  1. /*-----------------------DELCOL.EXE--------------By Steve Elliott---10-3-92-*/
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. void directions(void);
  5. unsigned int linecount = 0;
  6. main(int argc, char *argv[]){
  7. FILE *fp1;
  8. FILE *fp2;
  9. char *c;
  10. char oneword[100];
  11. char infile[14];
  12. char outfile[14];
  13. char ctmp[4];
  14. char atmp[4];
  15. unsigned int xcol = 1;
  16. unsigned int xamount = 0;
  17. unsigned int index;
  18. if(argc < 4)directions();
  19.  
  20. if(argc < 4){do{
  21.    printf("Enter input name  -> ");
  22.    scanf("%s",infile);         /* read the desired name */
  23.    fp1 = fopen(infile,"r");
  24.    }while(fp1 == 0);
  25.    
  26.    printf("Enter output name -> ");
  27.    scanf("%s",outfile);         /* read the desired name */
  28.    fp2 = fopen(outfile,"a");
  29.  
  30.    printf("Enter the first column to delete   #? ");
  31.    scanf("%s",ctmp);         /* read the desired column to delete*/
  32.    xcol = atoi(ctmp);
  33.  
  34.    printf("Enter the last  column to delete   #? ");
  35.    scanf("%s",atmp);  /* read the desired columns from xcol to delete */
  36.    xamount = atoi(atmp);
  37.  
  38.    if(xamount < xcol)xamount = xcol;
  39. }
  40.  
  41.  else {  fp1 = fopen(argv[1],"r"); fp2 = fopen(argv[2],"a");
  42.           xcol = atoi(argv[3]); 
  43.             if(argc == 3)xamount = xcol;
  44.             else { xamount = atoi(argv[4]);
  45.                    if(xamount < xcol)xamount = xcol;}
  46. }
  47.       xcol--;
  48.       xamount--;
  49.  do {
  50.   c = fgets(oneword,100,fp1); /* get one line from the file */
  51.    if (c != NULL){ for(index = 0;oneword[index] != 0;index++)
  52.     if((index < xcol) || (index > xamount))fprintf(fp2,"%c",oneword[index]);
  53.      else if(oneword[index] == 10)fprintf(fp2,"\n");
  54.  
  55.  
  56.     }
  57.  
  58. if(argc < 2 ){linecount++; printf("\rLine count ==  %d  ",linecount);}
  59.    } while (c != NULL);          /* repeat until NULL          */
  60. fclose(fp1);
  61. fclose(fp2);
  62. } /*-----------------------------------------END---------------------------*/
  63.  
  64. void directions(void){
  65. printf("\n\n\n\n\n\n\n\n\n\n\n                            <<< FREEWARE >>>\n\n");
  66. printf("                               DELCOL.EXE\n");
  67. printf("        Command line SYNTAX = DELCOL INFILE.EXT OUTFILE.EXT F# L#\n");
  68. printf("     F# = Column number to delete or First column number to delete.\n");
  69. printf("    L# = Column to delete to.  If left out, only column F# is deleted.\n");
  70. printf("  If no command line input is entered or it is entered wrong you will be\n");
  71. printf(" prompted for INFILE.EXT OUTFILE.EXT F# L# . So DELCOL.EXE can be run from\n");
  72. printf("   a batch file, command line, or just start the program and enter input.\n");
  73. printf("                             SHORT DIRECTIONS\n");
  74. printf("  Enter your file with your ASCII file editor, put the cursor on the first\n");
  75. printf("   column you want deleted, write down the file name & column number the\n");
  76. printf("   cursor is on, then put the cursor on the last colunm you want deleted\n");
  77. printf(" write the number, & start DELCOL. Enter the infilename.ext & outfilename.\n");
  78. printf(" Enter your first del column #, & enter the last del column # , that's it.\n");
  79. printf("     FREEWARE comes with no gaurentees. Get your input column #'s right.\n");
  80. printf("                           Press CTRL-C to abort.\n");
  81. printf("                    DELCOL.EXE  BY Steve Elliott 10-3-92\n\n\n");
  82. }
  83.